Skip to content

Start documenting error handling in coding guidelines#50

Draft
rousskov wants to merge 12 commits into
squid-cache:mainfrom
measurement-factory:SQUID-111-error-reporting-guidelines
Draft

Start documenting error handling in coding guidelines#50
rousskov wants to merge 12 commits into
squid-cache:mainfrom
measurement-factory:SQUID-111-error-reporting-guidelines

Conversation

@rousskov

Copy link
Copy Markdown
Contributor

No description provided.

@rousskov rousskov marked this pull request as draft July 13, 2026 00:46
@rousskov

Copy link
Copy Markdown
Contributor Author

Marking as a draft because I do not know how to test how this markup is going to be rendered on the web site.

@rousskov

Copy link
Copy Markdown
Contributor Author

Several key decisions in these proposed guidelines were driven by unofficial notes at https://github.com/measurement-factory/squid-notes/blob/start/errors.md

@kinkie

kinkie commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

LGTM in level of detail and to drive AI; it feels a bit verbose to include in the main coding guidelines. Would it be sensible to move it to its own page?

@rousskov

Copy link
Copy Markdown
Contributor Author

it feels a bit verbose to include in the main coding guidelines. Would it be sensible to move it to its own page?

Yes, I think it would, with a couple of bullet points remaining in SquidCodingGuidelines, so that folks reading our guidelines can discover the essential requirements (and then find the details on a dedicated page). I will adjust this PR to implement your suggestion.

@rousskov rousskov removed the request for review from kinkie July 14, 2026 14:50
Co-authored-by: Francesco Chemolli <kinkie@squid-cache.org>
@rousskov rousskov changed the title Start documenting error handling in SquidCodingGuidelines Start documenting error handling in coding guidelines Jul 14, 2026
@rousskov

Copy link
Copy Markdown
Contributor Author

it feels a bit verbose to include in the main coding guidelines. Would it be sensible to move it to its own page?

Yes, I think it would, with a couple of bullet points remaining in SquidCodingGuidelines, so that folks reading our guidelines can discover the essential requirements (and then find the details on a dedicated page). I will adjust this PR to implement your suggestion.

Done in 235f7b2. Still untested.

@rousskov rousskov requested a review from kinkie July 14, 2026 15:46
Comment on lines +20 to +22
allowed, but Squid currently avoids explicit `constexpr`, and sprinkling
Squid code with many `constexpr` specifiers to get some compile-time
assertion working is usually a bad idea.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"avoids" implies that we have some sort of agreement not to use that construct. Reality is that no Squid contributor has considered it worth converting any of the code to using it.

I suggest leaving it at: (no more than) minor adjustments being acceptable.

Suggested change
allowed, but Squid currently avoids explicit `constexpr`, and sprinkling
Squid code with many `constexpr` specifiers to get some compile-time
assertion working is usually a bad idea.
allowed, but these should not extend nor exceed the minimal scope of logic change.

Comment on lines +32 to +33
sent a syntactically valid HTTP request to Squid"), do not use any of the
above calls. Instead, create and throw a `TextException` object, return

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"if X, do not use any of the above" - directly contradicts the initial requirement "pick the first one that matches your use case".

This whole clause/condition is not clearly distinguished from the prior "code invariant" clause. Likely because this item is about transactional / protocol flow behaviour; whereas the prior clauses are about catching code logic errors.

Comment on lines +115 to +117
request is actually dedicated to upgrading legacy code. In those exceptional
cases, the author becomes responsible for providing a high quality
replacement, of course.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
request is actually dedicated to upgrading legacy code. In those exceptional
cases, the author becomes responsible for providing a high quality
replacement, of course.
request is actually dedicated to upgrading legacy code.

Code quality is subjective and your definition has proven to be both controversial and problematic. Do not make it a requirement for Squid contributors to meet that impossible bar. Remember that we have the officially core/board agreed policy that "good enough" is permissible - "high quality" is an Alex review thing, not a Squid code requirement.

## Other special cases

`Assure()` is not available in code residing outside of `src/`, in helper code
that has not been upgraded to use `src/base` APIs, and in legacy C code. Use

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
that has not been upgraded to use `src/base` APIs, and in legacy C code. Use
that has not been upgraded to use `src/base` APIs, and in legacy C-style callbacks. Use

The only actual "legacy C code" is outside src/ now, so strictly speaking that would be redundant text. However I suspect you actually mean the legacy code in src/ which is using the old C-style mechanisms. Of which the most notable are callbacks. If there are others, it might be worth enumerating theme here and also as items to fix in the contributor TODO list.

* Legacy `TexcHere()` is a convenience macro. Modern code spells out
`TextException` and `Here()` explicitly.

Keep in mind that it is usually best to leave legacy code intact. Upgrading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that it is usually best to leave legacy code intact.

Hmm, this statement implies that you have seriously misunderstood the Best Practice principle of leaving old code alone. The purpose of which is actually to prevent young/new developers a) unnecessarily introducing bugs with code change, b) removing necessary bug workarounds while cleaning "messy" legacy code, or c) re-re-upgrading the same code to "latest new thing" in a loop instead of fixing underlying problems.
The practice only holds true when a) the developer is ignorant of the old code purpose and issues within, or b) the replacement "latest thing" is not yet proven to be better code.

The Squid code has reached the pace where almost all code is now outdated "legacy" patched together by layers of technical debt (eg wrapper macros and functions). Leaving the technical debt intact has long since stopped being a good thing.

Comment on lines +126 to +128
The following error handling functions are not covered by this documentation.
They should be avoided in most cases, especially in new code: `fatalf()`,
`fatal()`, `fatal_dump()`, `xassert()`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the same paradigm as the Must() etc, items you put in "Legacy error handling". Please either
Either;

  • document all of the mechanisms currently existing (even deprecated ones), or
  • omit the legacy/deprecated items entirely (proposed text about them in the SquidCodingGuidelines page is sufficient).

The author should exclusively use whatever of the mechanisms documented on this page are appropriate for their new/changed code.

Comment on lines +70 to +71
* Do not use deprecated `Must()`, `Must3()`, fatalf()`, `fatal()`, and
`fatal_dump()` in new code. See

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing xassert() and TexcHere()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants